﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Configuration;
using Estimate.Common.Estimate;
using Estimate.Common.DBFieldTypes;
using Estimate.Common.Entity;
using Estimate.Common.DataFileFinder;
using Estimate.Reports;

namespace EstimateService
{
    /// <summary>
    /// Test 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务，请取消注释以下行。 
    // [System.Web.Script.Services.ScriptService]
    public class Test : System.Web.Services.WebService
    {
        [WebMethod]
        public string TestTempDiagramReportData(string date, string station, string sendpoint, string span, string tid)
        {

            date = "2014-06-20";
            station = "58036";
            sendpoint = "H06";
            span = "120";
            tid = "";
            string connectionString = ConfigurationManager.AppSettings["ConnectionString"];
            string tablestr = ConfigurationManager.AppSettings["TempDiagramTables"];

            Dictionary<string, string> tables = new Dictionary<string, string>();
            foreach (string s in tablestr.Split('|'))
            {
                string[] strs = s.Split(';');
                tables.Add(strs[0], strs[1]);
            }


            DateTime dateTime = DateTime.Parse(date);
            ForeSendpointType sendPoint = (ForeSendpointType)Enum.Parse(typeof(ForeSendpointType), sendpoint);
            //ForeSpanType foreSpan = (ForeSpanType)Enum.Parse(typeof(ForeSpanType), span);

            TempDiagramReport tempDiagramReport = new TempDiagramReport(connectionString, tid);
            return tempDiagramReport.GetReportDataString(tables, dateTime, span, station, sendPoint);
        }

        //[WebMethod]
        //public string TestExecutionStatus()
        //{
        //    ExecutionStatus exestatus = new ExecutionStatus();

        //    return exestatus.GetStatusFromCache("86c6c3eb-810a-42ec-bf22-6f71883c1e9c");
        //}

        //[WebMethod]
        //public string TestUsuallyReport()
        //{
        //    DateTime startDate = DateTime.Parse("2013-11-01");
        //    DateTime endDate = DateTime.Parse("2013-11-30");
        //    string connectionString = ConfigurationManager.AppSettings["ConnectionString"];
        //    UsuallyReport report = new UsuallyReport(connectionString);
        //    string scorelist = "";
        //    report.PrepareData(startDate, endDate);
        //    scorelist = report.GetReportDataString();
        //    return scorelist;
        //}

        //[WebMethod]
        //public string TestStForecasterRankReport()
        //{
        //    string connectionString = ConfigurationManager.AppSettings["ConnectionString"];

        //    DateTime beginDate = DateTime.Parse("2013-01-01");
        //    DateTime endDate = DateTime.Parse("2013-12-31");
        //    ForeSemiType semiType = (ForeSemiType)Enum.Parse(typeof(ForeSemiType), "Auto");
        //    ForeSpanType[] spans = new ForeSpanType[] { ForeSpanType.FD00_24, ForeSpanType.FD24_48 };
        //    string sendpoints = "H06,H16";
        //    //string forecasters = "zhoubj,suny,jinxx,jiangl,zhaok,yaoln,zhaoqh,jiangyf,yanwl,wangxh,yindp,yujw,sunhc,lic,zhangj,hangr,wuhy,yuly,zongps,wangy,zhangzq,weijs,weiw,yangty,caol,liuan,wangjr,yanml,qinmr,caosy,lium";
        //    string forecasters = "zhaok";
        //    string tid = "86c6c3eb-810a-42ec-bf22-6f71883c1e9c";
        //    List<ForeSendpointType> sendpointList = new List<ForeSendpointType>();
        //    foreach (string s in sendpoints.Split(','))
        //        sendpointList.Add((ForeSendpointType)Enum.Parse(typeof(ForeSendpointType), s.Replace("'", "")));
        //    ForeSendpointType[] sendpointArray = sendpointList.ToArray();

        //    ForecasterRankReport stForecasterRankReport = new ForecasterRankReport(forecasters.Split(','), connectionString, tid);
        //    stForecasterRankReport.PrepareData(beginDate, endDate, spans, sendpointArray, semiType);
        //    return stForecasterRankReport.GetReportDataString();
        //}

        //[WebMethod]
        //public string TestIndividualRankReport()
        //{
        //    string connectionString = ConfigurationManager.AppSettings["ConnectionString"];
        //    float proportion = float.Parse(ConfigurationManager.AppSettings["Proportion"]);

        //    DateTime beginDate = DateTime.Parse("2013-01-01");
        //    DateTime endDate = DateTime.Parse("2013-12-31");
        //    ForeSemiType semiType = (ForeSemiType)Enum.Parse(typeof(ForeSemiType), "Auto");
        //    ForeSpanType[] spans = new ForeSpanType[] { ForeSpanType.FD00_24, ForeSpanType.FD24_48 };
        //    string sendpoints = "H06,H16";
        //    //string forecasters = "58238_11,58238_12,58238_15,58238_16,58238_17,58238_18,58238_19,58238_20,58238_21,58238_23,58238_26,58238_27,58238_28,58238_29,58238_30,58238_31,58238_32,58238_33";
        //                         // 58238_11,58238_12,58238_15,58238_16,58238_17,58238_18,58238_19,58238_20,58238_21,58238_23,58238_26,58238_27,58238_28,58238_29,58238_30,58238_31,58238_32,58238_33
        //    string forecasters = "58027_31,58027_29,58027_25,58027_24,58027_26,58027_27,58027_30,58027_33,58027_36,58027_32,58044_22,58044_27,58044_8,58044_10,58044_20,58044_31,58044_5,58044_28,58044_4,58131_207,58131_215,58131_218,58131_216,58131_219,58131_212,58141_335,58141_328,58141_326,58141_336,58141_331,58141_327,58141_223,58141_339,58151_18,58151_21,58151_22,58151_26,58151_28,58151_29,58151_33,58151_36,58151_15,58238_11,58238_12,58238_15,58238_16,58238_17,58238_18,58238_19,58238_20,58238_21,58238_23,58238_26,58238_27,58238_28,58238_29,58238_30,58245_66,58245_37,58245_15,58245_10,58245_22,58245_18,58245_13,58246_12,58246_9,58246_23,58246_24,58252_6,58252_8,58252_16,58252_17,58252_18,58252_19,58252_20,58252_21,58252_26,58252_28,58259_9,58259_10,58259_12,58259_16,58259_19,58259_20,58259_21,58259_25,58259_26,58343_23,58343_29,58343_32,58343_33,58343_35,58343_36,58343_37,58343_39,58354_98,58354_19,58354_27,58354_8,58354_10,58354_11,58354_66,58354_15,58354_20,58357_28,58357_77,58357_72,58357_41,58357_73,58357_19,58357_33,58357_78,58357_9,58245_23,58246_16,58259_22,58259_23,58141_337,58141_340,58151_32,58245_11,58343_40,58343_31,58252_27,58246_25,58131_220,58131_221,58357_15,58357_21,58357_26,58357_66,58151_39,58044_12,58044_7";
        //    //string forecasters = "58238_20";
        //    //string forecasters= "58252_6,58252_8,58252_16,58252_17,58252_18,58252_19,58252_20,58252_21,58252_26,58252_28,58252_27";
        //    string tid = "86c6c3eb-810a-42ec-bf22-6f71883c1e9c";
        //    List<ForeSendpointType> sendpointList = new List<ForeSendpointType>();
        //    foreach (string s in sendpoints.Split(','))
        //        sendpointList.Add((ForeSendpointType)Enum.Parse(typeof(ForeSendpointType), s.Replace("'", "")));
        //    ForeSendpointType[] sendpointArray = sendpointList.ToArray();

        //    IndividualRankReport forecasterRankReport = new IndividualRankReport(forecasters, connectionString,proportion, tid);
        //    forecasterRankReport.PrepareData(beginDate, endDate, semiType);
        //    return forecasterRankReport.GetReportDataString();
          
        //}

        //[WebMethod]
        //public string TestIndividualReport()
        //{
        //    string connectionString = ConfigurationManager.AppSettings["ConnectionString"];

        //    DateTime beginDate = DateTime.Parse("2013-12-01");
        //    DateTime endDate = DateTime.Parse("2013-12-31");
        //    ForeSemiType semiType = (ForeSemiType)Enum.Parse(typeof(ForeSemiType), "Auto");
          
        //    string sendpoints = "H06,H16";
        //    string forecaster = "58354_11";
        //    string tid = "86c6c3eb-810a-42ec-bf22-6f71883c1e9c";
        //    List<ForeSendpointType> sendpointList = new List<ForeSendpointType>();
        //    foreach (string s in sendpoints.Split(','))
        //        sendpointList.Add((ForeSendpointType)Enum.Parse(typeof(ForeSendpointType), s.Replace("'", "")));
        //    ForeSendpointType[] sendpointArray = sendpointList.ToArray();

        //    IndividualReport individualReport = new IndividualReport(forecaster, connectionString, tid);
        //    individualReport.PrepareData(beginDate, endDate, sendpointArray, semiType);
        //    return individualReport.GetReportDataString();
        //}

        //[WebMethod]
        //public string TestStIndividualReport()
        //{
        //    string begindate = "2012-01-01";
        //    string enddate = "2013-12-31";
        //    string semitype = "Auto";
        //    string sendpoints = "H06,H16";
        //    string forecaster = "zongps";
        //    string tid = "86c6c3eb-810a-42ec-bf22-6f71883c1e9c";
        //    string connectionString = ConfigurationManager.AppSettings["ConnectionString"];

        //    DateTime beginDate = DateTime.Parse(begindate);
        //    DateTime endDate = DateTime.Parse(enddate);
        //    ForeSemiType semiType = (ForeSemiType)Enum.Parse(typeof(ForeSemiType), semitype);

        //    List<ForeSendpointType> sendpointList = new List<ForeSendpointType>();
        //    foreach (string s in sendpoints.Split(','))
        //        sendpointList.Add((ForeSendpointType)Enum.Parse(typeof(ForeSendpointType), s.Replace("'", "")));
        //    ForeSendpointType[] sendpointArray = sendpointList.ToArray();

        //    STIndividualReport sTIndividualReport = new STIndividualReport(forecaster, connectionString, tid);
        //    sTIndividualReport.PrepareData(beginDate, endDate, sendpointArray, semiType);
        //    return sTIndividualReport.GetReportDataString();
        //}

        [WebMethod]
        public string TestForecasterRankReportData(string begindate, string enddate, string sendpoints, string wthspans, string tempspans, string forecasters, string stations, string tid)
        {
            begindate = "2014-11-01";
            enddate = "2014-11-30";
            sendpoints = "H06,H10,H16";

            forecasters = "haol,macc,baix,qxt,wanggc,zhanghh,zhangyy,zhumh,zhuyf";
            
            string connectionString = ConfigurationManager.AppSettings["ConnectionString"];

            DateTime beginDate = DateTime.Parse(begindate);
            DateTime endDate = DateTime.Parse(enddate);
            ForeSemiType semiType = ForeSemiType.Auto;
          

            ForeSpanType[] spans = new ForeSpanType[] { ForeSpanType.FD00_24, ForeSpanType.FD24_48 };
            List<ForeSendpointType> sendpointList = new List<ForeSendpointType>();
            foreach (string s in sendpoints.Split(','))
                sendpointList.Add((ForeSendpointType)Enum.Parse(typeof(ForeSendpointType), s.Replace("'", "")));
            ForeSendpointType[] sendpointArray = sendpointList.ToArray();

            ForecasterRankReport forecasterRankReport = new ForecasterRankReport(forecasters.Split(','), connectionString, tid);
            forecasterRankReport.PrepareData(beginDate, endDate, spans, sendpointArray, semiType);
            return forecasterRankReport.GetReportDataString();

        }


        [WebMethod]
        public string TestStandardReportData1(string begindate, string enddate, string sendpoints, string wthspans, string tempspans, string memberTable, string standardTable, string stations, string tid)
        {
            begindate = "2014-07-01";
            enddate = "2014-07-30";
            sendpoints = "H06,H10,H16";
            wthspans = "FD00_12,FD12_24,FD00_24";
            tempspans = "FD00_24";
            stations = "58044";
            memberTable = "EC_ThinFore";
            standardTable = "EnsembleFore";
            string connectionString = ConfigurationManager.AppSettings["ConnectionString"];

            DateTime beginDate = DateTime.Parse(begindate);
            DateTime endDate = DateTime.Parse(enddate);
          
            ForeSemiType semiType = ForeSemiType.Auto;
            //DataTableType tableName = (DataTableType)Enum.Parse(typeof(DataTableType), tablename);


            List<ForeSendpointType> sendpointList = new List<ForeSendpointType>();
            foreach (string s in sendpoints.Split(','))
                sendpointList.Add((ForeSendpointType)Enum.Parse(typeof(ForeSendpointType), s.Replace("'", "")));
            ForeSendpointType[] sendpointArray = sendpointList.ToArray();

            List<ForeSpanType> spanList = new List<ForeSpanType>();
            foreach (string s in wthspans.Split(','))
                spanList.Add((ForeSpanType)Enum.Parse(typeof(ForeSpanType), s.Replace("'", "")));
            ForeSpanType[] wthSpanArray = spanList.ToArray();

            spanList.Clear();
            foreach (string s in tempspans.Split(','))
                spanList.Add((ForeSpanType)Enum.Parse(typeof(ForeSpanType), s.Replace("'", "")));
            ForeSpanType[] tempSpanArray = spanList.ToArray();


            StandardReport standardReport = new StandardReport(connectionString, memberTable, standardTable, stations, tid);
            standardReport.PrepareData(beginDate,endDate, semiType, wthSpanArray, tempSpanArray, sendpointArray,true);
            return standardReport.GetReportDataString();

        }

        [WebMethod]
        public string GetForeProductRankReportData(string begindate, string enddate, string sendpoints, string semitype, string tid)
        {
             begindate = "2014-05-01";
             enddate = "2014-07-31";
             semitype = "Auto";
             sendpoints = "H06,H16";

            string connectionString = ConfigurationManager.AppSettings["ConnectionString"];
            string foreproductsString = ConfigurationManager.AppSettings["TempDiagramTables"];

            Dictionary<string, string> foreproducts = new Dictionary<string, string>();
            foreach (string s in foreproductsString.Split('|'))
            {
                string[] strs = s.Split(';');
                foreproducts.Add(strs[0], strs[1]);
            }

            DateTime beginDate = DateTime.Parse(begindate);
            DateTime endDate = DateTime.Parse(enddate);
            ForeSemiType semiType = (ForeSemiType)Enum.Parse(typeof(ForeSemiType), semitype);
            ForeSpanType[] spans = new ForeSpanType[] { ForeSpanType.FD00_24, ForeSpanType.FD24_48 };
            List<ForeSendpointType> sendpointList = new List<ForeSendpointType>();
            foreach (string s in sendpoints.Split(','))
                sendpointList.Add((ForeSendpointType)Enum.Parse(typeof(ForeSendpointType), s.Replace("'", "")));
            ForeSendpointType[] sendpointArray = sendpointList.ToArray();

            ForeProductRankReport foreProductRankReport = new ForeProductRankReport(foreproducts, connectionString, tid);

            foreProductRankReport.PrepareData(beginDate, endDate, spans, sendpointArray, semiType);
            return foreProductRankReport.GetReportDataString();

        }

        [WebMethod]
        public string GetForeCompareReportData(string begindate, string enddate, string sendpoints, string wthspans, string tempspans, string forecaster, string foreproducts, string station, string tid)
        {
            begindate = "2014-11-25";
            enddate = "2014-11-30";
            sendpoints = "H06,H10,H16";
            wthspans = "FD00_24,FD24_48,FD48_72";
            tempspans = "FD00_24,FD24_48,FD48_72";
            station = "58044";
            forecaster = "wanggc";
            foreproducts = "NmcFore";

            string connectionString = ConfigurationManager.AppSettings["ConnectionString"];

            DateTime beginDate = DateTime.Parse(begindate);
            DateTime endDate = DateTime.Parse(enddate);
            ForeSemiType semiType = ForeSemiType.Auto;

            List<ForeSendpointType> sendpointList = new List<ForeSendpointType>();
            foreach (string s in sendpoints.Split(','))
                sendpointList.Add((ForeSendpointType)Enum.Parse(typeof(ForeSendpointType), s.Replace("'", "")));
            ForeSendpointType[] sendpointArray = sendpointList.ToArray();


            List<ForeSpanType> spanList = new List<ForeSpanType>();
            foreach (string s in wthspans.Split(','))
                spanList.Add((ForeSpanType)Enum.Parse(typeof(ForeSpanType), s.Replace("'", "")));
            ForeSpanType[] wthSpanArray = spanList.ToArray();

            spanList.Clear();
            foreach (string s in tempspans.Split(','))
                spanList.Add((ForeSpanType)Enum.Parse(typeof(ForeSpanType), s.Replace("'", "")));
            ForeSpanType[] tempSpanArray = spanList.ToArray();

            ForeSendpointType[] sendPoints = new ForeSendpointType[] { ForeSendpointType.H06, ForeSendpointType.H16 };

            List<string> foreProducts = new List<string>();

            foreach (string foreProduct in foreproducts.Split(','))
                foreProducts.Add(foreProduct);

           

            ForeCompareForeReport foreCompareForeReport = new ForeCompareForeReport(connectionString, forecaster, foreProducts, station, tid, false);

            foreCompareForeReport.PrepareData(beginDate, endDate, semiType, wthSpanArray, tempSpanArray, sendpointArray, true);

            return foreCompareForeReport.GetReportDataString(false);
        }



    }
}
